<template>
  <div :class="className" style="min-height: 667px;">
    <!-- style -->
    <div v-html="css"></div>

    <div class="tab-box" v-if="datas.list">
      <div class="tab-left-list" v-if="datas.show_first_tab">
        <div class="tab-left-item" :class="[index == 0 ? 'active' :'']" v-for="(item,index) in datas.list">
          <img v-if="item.image" class="tab-left-img" :src="item.image" alt="">
          <span v-if="!item.image" :style="{textIndent: item.text.length==5?'5px':'',padding: item.text.length==4?'0 5px':''}" class="tab-left-title">{{item.text}}</span>
        </div>
      </div>

      <div class="tab-content-box">
        <div class="tab-content" v-for="(item) in datas.list">
          <div class="tab-top-choose" v-if="datas.is_show_first_tab_title || datas.show_second_tab">
            <div class="top-title" v-if="datas.is_show_first_tab_title"><span class="line"></span><span>{{item.text}}</span></div>
            <div class="top-option-list" :class="[datas.show_first_tab?'show_first_tab':'not_show_first_tab']" v-if="datas.show_second_tab">
              <span class="top-option-item" :class="[i == 0 ? 'active' :'']" v-for="(second,i) in item.second_list">{{second.title}}</span>
              <span class="top-option-item" v-if="item.second_list.length>7">换一换 <i class="iconfont icon-fontclass-tequanzhekou"></i></span>
            </div>
          </div>
          <div class="tab-group" v-if="item.second_list[0]">
            <div class="tab-item" v-for="(component, index) in item.second_list[0].components" :key="index">
              <component
                  :is="component.uikey"
                  :id="id+'-'+index"
                  :componentWidth="datas.show_first_tab?325:375"
                  :datas="handleDatas(component.datas)"
                  :languages="languages">
              </component>
              <div class="check-more" v-if="component.uikey==='U_goods'">查看更多</div>
            </div>
          </div>
        </div>
      </div>

    </div>
    <div v-if="datas.list && datas.list.length <= 0" style="padding: 15px;text-align: center">
      暂无设置选项卡
    </div>
  </div>
</template>

<script>
	import emptyImage from "@/resource/images/banner.png";
// 自定义样式
const css = function() {
  const {
	  preview_color,
	  first_tab_color,
	  first_tab_bg_color,
	  first_tab_active_color,
	  first_tab_active_bg_color,
	  first_tab_title_color,
	  second_tab_color,
	  second_tab_bg_color,
	  second_tab_active_color,
	  second_tab_active_bg_color,
	  show_second_border,
	  second_border_color,
	  check_more_color,
	  check_more_bg_color,
  } = this.datas;

  return `
        .component-${this.id}  .tab-box {
            background-color: ${preview_color};
        }
        .component-${this.id} .tab-left-list{
            background-color: ${first_tab_bg_color};
            color: ${first_tab_color};
        }

        .component-${this.id} .tab-left-list .active{
            background-color: ${first_tab_active_bg_color};
            color: ${first_tab_active_color};
        }

        .component-${this.id} .top-title {
            color: ${first_tab_title_color};
        }
        .component-${this.id} .tab-top-choose .line {
            background-color: ${first_tab_title_color};
        }

        .component-${this.id} .top-option-item {
            background-color: ${second_tab_bg_color};
            color: ${second_tab_color};
            border: ${show_second_border? 1 : 0}px solid ${second_border_color};
        }

        .component-${this.id} .top-option-item.active {
            background-color: ${second_tab_active_bg_color};
            color: ${second_tab_active_color};
        }

        .component-${this.id} .check-more {
            background-color: ${check_more_bg_color};
            color: ${check_more_color};
        }
    `;
};

export default {
  data() {
    return {
	    emptyImage,
    };
  },
  props: ["id", "datas", "styles"],
  computed: {
    css() {
      return "<style>" + css.call(this) + "</style>";
    },
    className() {
      const name = ["component-wrapper", `component-${this.id}`];
      return name;
    },
	  /**
	   * 语言包
	   * @return {object}
	   */
	  languages () {
		  return this.$store.state.page.languages || {};
	  }
  },

  methods: {
	  // 功能数据
	  handleDatas (old_data) {
		  // 如果有配置项的话
		  let datas = {};
		  if (old_data) {
			  Object.keys(old_data).map(key => {
				  datas[key] = old_data[key].value;
			  });
		  }
		  return datas;
	  },
    // rem转换
    px2rem(val = 0) {
      return val / 75 + "rem";
    },
  },

  mounted() {
    this.$emit("loaded");
  },
};
</script>

<style lang="less" scoped>
// 默认
* {
  list-style-type: none;
}
.component-wrapper {
  width: 375px;
}
#tab {
  .nav {
    display: flex;
    align-items: center;
    height: 40px;
    white-space: nowrap;
    flex-wrap: nowrap;
    box-sizing: content-box;
    .nav-li {
      flex: 1;
      min-width: 20%;
      text-align: center;
      .nav-lis {
        display: inline-block;
        line-height: 40px;
      }
    }
  }

  .scroll {
    overflow-x: scroll;
  }
}

  .tab-box {
    display: flex;
  }
  .tab-left-list {
    display: flex;
    flex-direction: column;
    flex: 0 0 50px;
    text-align: center;
    .tab-left-item {
      font-size: 12px;
      padding: 15px 5px;
    }
    .tab-left-title {
      display: inline-block;
    }
    /*.tab-left-item.active {*/
      /*background-color: #333333;*/
      /*color: #ffffff;*/
    /*}*/
    .tab-left-img {
      width: 100%;
      height: 100%;
    }
  }
  .tab-content-box {
    flex: 1;
    display: flex;
    flex-direction: column;
  }
  .tab-content {
    display: flex;
    flex-direction: column;
  }
  .tab-top-choose {
    padding: 10px 5px;
    .top-title {
      display: flex;
      align-items: center;
      margin-bottom: 5px;
    }
    .line {
      width: 2px;
      height: 16px;
      /*background-color: #333333;*/
      margin-right: 8px;
    }
    .top-option-list {
      font-size: 12px;
    }
    .top-option-list.show_first_tab {
      display: flex;
      flex-wrap: wrap;
    }
    .top-option-list.not_show_first_tab {
      white-space: nowrap;
      overflow-x: scroll;
    }
    .top-option-list::-webkit-scrollbar {display:none}
    .top-option-item {
      display: inline-block;
      padding: 3px 10px;
      /*border: 1px solid #333333;*/
      border-radius: 2px;
      margin: 3px;
    }
    /*.top-option-item.active {*/
      /*background-color: #333333;*/
      /*color: #ffffff;*/
    /*}*/
    .icon-fontclass-tequanzhekou {
      font-size: 12px;
      vertical-align: middle;
    }
  }
  .tab-group {
    .check-more {
      width: 80%;
      height: 35px;
      margin: 20px auto;
      text-align: center;
      line-height: 35px;
      /*background-color: #333333;*/
      /*color: #ffffff;*/
      border-radius: 4px;
    }
  }
</style>
